<!DOCTYPE html>
<html>
<head>
	
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title>蹭一族</title>
	<!-- Bootstrap 3.3.5 -->
  <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css"  />
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/static/awesome/css/font-awesome.min.css" /> 
  <!-- Ionicons -->
  <link rel="stylesheet" href="/static/ionicon/css/ionicons.min.css" />
  <!-- DataTables -->
  <link rel="stylesheet" href="/static/plugins/datatables/dataTables.bootstrap.css">
   <!-- DataTables -->
  <link rel="stylesheet" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/static/dist/css/AdminLTE.min.css" />
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="/static/dist/css/skins/_all-skins.min.css" />
  
    <link rel="stylesheet" href="/static/js/img/img.css" type="text/css">
    
    
<link href="/static/bootstrapValidate/css/bootstrapValidator.min.css" rel="stylesheet" />
 <!-- daterange picker -->
  <link rel="stylesheet" href="/static/plugins/daterangepicker/daterangepicker-bs3.css">

 <style>
 	tbody tr td{ text-align:center; }
 </style>

<!-- ./wrapper -->	

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
	<#-- header -->
  <#include  "/store/layouts/header.ftl" >
  
  <div class="content-wrapper">
  
  <section class="content-header">
      <h1>
        <span></span>
        <small>订单列表</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="/manager/${sys}"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active"   >订单列表</li>
      </ol>
    </section>
 	 <#-- 左侧导航栏-->
  	<#if Session.session_admin_user['ROLE_CODE']=='store'>
 	 	<#include  "/store/menu/sidebar_store.ftl" />
	</#if>
    <#-- 内容 -->
    <section class="content"  >
       <table>
       		<tr>
       			<td>
       				<a class="btn btn-app" onclick="exportFun()" >
	                	<i class="fa fa-plus"></i> 导出订单
	              	</a>
       			</td>
       			<#--
       				<td>
       				<a class="btn btn-app" onclick="addFun()" >
	                	<i class="fa fa-plus"></i> 添加
	              	</a>
       			</td>
       			<td>
       				<a class="btn btn-app" onclick="editFun()" >
	                	<i class="fa fa-edit"></i> 修改
	              	</a>
       			</td>
       			 <td>
       				<a class="btn btn-app" onclick="delFun()"  >
	                	<i class="fa fa-minus"></i> 删除
	              	</a>
       			</td>
       			-->
       		</tr>
       </table>
    
       <table id="datatable" class="table table-bordered table-striped">
                <thead>
	                <tr >
	                  <th>订单编号</th>
	                  <th>订单金额</th>
	                  <th>购买用户</th>
	                  <th>商家名</th>
	                  <th>支付方式</th>
	                  <th>订单类型</th>
	                  <th>订单状态</th>
	                  <th>优惠券</th>
	                  <th>酒水减免</th>
	                  <th>操作</th>
	                  <th>创建时间</th>
	                </tr>
                </thead>
        </table>
      
    </section>
  </div>
  
  
  <#-- /.content-wrapper -->
  <#include "/admin/layouts/footer.ftl" />

  <#-- Control Sidebar -->
  <#include  "/admin/layouts/controlSidebar.ftl" />
</div>

<!-- jQuery 2.1.4 -->
<script src="/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="/static/js/jqueryUi.min.1.11.4.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<!-- Bootstrap 3.3.5 -->
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<!-- Morris.js charts 
<script src="/static/plugins/morris/morris.min.js"></script>
-->

<!-- DataTables -->
<script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- Slimscroll -->
<script src="/static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="/static/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="/static/dist/js/app.min.js"></script>

<#-- AdminLTE for demo purposes -->
<script src="/static/dist/js/demo.js"></script>
<!-- layer-->
<script src="/static/layer/layer.js"></script>

<!-- layer-->
<script src="/static/js/syUI.js"></script>


<script type="text/javascript" src="/static/js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/static/js/uploadify/jquery.uploadify.js"></script>
<!-- 引入ui扩展 -->
<script src="/static/js/core.ui.js" type="text/javascript" charset="utf-8"></script>
<!-- 引入图片裁剪-->
<link rel="stylesheet" href="/static/js/tapmodo-Jcrop-1902fbc/css/jquery.Jcrop.css" type="text/css">
<script type="text/javascript" src="/static/js/tapmodo-Jcrop-1902fbc/js/jquery.Jcrop.js"></script>
<script type="text/javascript" src="/static/js/tapmodo-Jcrop-1902fbc/js/jquery.Jcrop.min.js"></script>
<!-- 浏览大图 -->
<script type="text/javascript" src="/static/js/img/img.js"></script>

<script type="text/javascript" src="/static/js/ut.js" ></script>

<script src="/static/bootstrapValidate/js/bootstrapValidator.min.js"></script>

<script src="/static/plugins/daterangepicker/moment.js"></script>
<script src="/static/plugins/daterangepicker/daterangepicker.js"></script>

<script>
	var type "";
	<#if type??>
		type = "${type}";
	</#if>
	var table ;
	var stateMap ={
		0:'已取消',
		1:'未付款',
		2:'已付款',
		3:'未知状态',
		4:'交易完成',
		5:'退款中',
		6:'退款成功',
		7:'退款失败',
		8:'订单异常',
		10:'订单异常'
		
	}
	$(function(){
		table = $("#datatable").dataTable({
	      "processing": true,
	      "serverSide": true,
	       ordering:false,
	      "ajax" : "/order/list?type="+type,
	       searching:false,
	       "oLanguage" : {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "商家名称:",
                "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
                }
            },
            "aoColumnDefs": [
			{
			 sDefaultContent: '',
			 aTargets: [ '_all' ]
			  }
			],
	      <!-- "fnServerData":retrieveData, //与后台交互获取数据的处理函数     
	      -->
	      "columns": [
	       <!-- {"data": "id",sWidth:'3%'},, "bSortable": false -->
	        {
	        	"data": "code",sWidth:'5%'
	        },{
	        	"data": "totalPay",sWidth:'8%',
	        	"render": function(data, type, full) {
	        		if(full.priceChange){
	        			return "¥"+(parseFloat(data)+parseFloat(priceChange));
	        		}
		            return "¥"+data;
		          }
	        },
	        {
	        	"data": "nickName",sWidth:'8%',
	        	"render": function(data, type, full) {
	        		if(data){
	        			return data+"("+full.username+")";
	        		}
		            return "";
		          }
	        },
	        {
	        	"data": "storeName",sWidth:'10%'
	        },
	        {
	        	"data": "payType",sWidth:'10%',
	        	"render": function(data, type, full) {
	        		if(!data) return "";
	        		if(data==1) return "在线支付";
	        		return "线下支付";
		          }
	        },
	        {
	        	"data": "type",sWidth:'10%',
	        	"render": function(data, type, full) {
	        		if(!data) return "";
	        		if(data==1) return "app订单";
	        		return "pad订单";
		          }
	        },
	        {
	        	"data": "state",sWidth:'10%',
	        	"render": function(data, type, full) {
	        		if(!data==undefined) return "";
	        		if(full.backState!=1){
	        			return stateMap[full.backState-1];
	        		}else{
	        			return stateMap[data];
	        		}
		          }
	        },
	        {
	        	"data": "couponValue",sWidth:'8%',
	        	"render": function(data, type, full) {
	        		if(data==undefined) return "";
	        		 return "满"+full.full+"减"+data;
		          }
	        },
	        {
	        	"data": "wineMoney",sWidth:'8%',
	        	"render": function(data, type, full) {
	        		if(data==undefined) return "";
	        		 return "¥"+data;
		          }
	        },
	        {
	        	"data": "isRecommend",sWidth:'5%',
	        	"render": function(data, type, full) {
	        		if('${sys}'=='store'){
	        		 	return "<button  onclick='editFun(\""+full.id+"\")' type='button' class='btn btn-block btn-primary'>编辑</button>";
	        		}
	        		if('${sys}'=='admin'){
	        		 	return "<button  onclick='seeFun(\""+full.id+"\")' type='button' class='btn btn-block btn-primary'>查看详情</button>";
	        		}
		         }
	        },
	        {"data": "createTime",sWidth:'8%'},
	      ]
	    });
	    
	    $("#datatable tbody").click(function (event) {
            $(table.fnSettings().aoData).each(function () {
                $(this.nTr).removeClass('selected');
            });
            $(event.target.parentNode).addClass('selected');
            
        });

        $('#datatable tbody tr').click(function (event) {
            var aData = table.fnGetData(this); // get datarow
            if (null != aData)  // null if we clicked on title row
            {
                var tt = aData[0];
                alert(tt);
               document.getElementById("Hidden1").value = tt;
            }
        });
        
        $('#datatable_wrapper').find('.row').eq(0).find('.col-sm-6').eq(1).append("<div style='float:right;' >"       		  
       		   +"<div class='input-group'><div class='input-group-addon'><i class='fa fa-calendar'></i></div>"
               +"<input type='text' class='form-control pull-right' id='reservation'></div></div>");
               
		var picker = $('#reservation').daterangepicker({language:'zh-CN',format:'YYYY-MM-DD'});
		 
		//选择时间后触发重新加载的方法
       $("#reservation").on('apply.daterangepicker',function(ret){
           //当选择时间后，出发dt的重新加载数据的方法
			var range = picker.val();   
			 var begin = "";
			 var end = "";
			 if(range){
			 	begin = range.split(' - ')[0]+' 00:00:00';
			 	end =  range.split(' - ')[1]+' 23:59:59';
			 }
			 sy.fnredraw({beginTime:begin,endTime:end},'/order/list?type='+type,table);
       });
        
	});
	
	var addFun = function(){
		var dialog = sy.modalDialog({
			title : '添加活动',
			width : '800',
			height : '600',
			url : '/manager/${sys}/go/indexActEdit',
			buttons : [ {
				text : '保存',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.submitForm(dialog, table, parent.$);
				}
			} ]
		});
	}
	var seeFun = function(tid){
		var dialog = sy.modalDialog({
			title : '查看订单商品',
			width : '800',
			height : '600',
			url : '/manager/${sys}/go/orderGoodsList?id='+tid,
			buttons : [ ]
		});
	}
	
	var editFun = function(){
		var rows = sy.fnGetSelected(table);
		if (rows.length != 1) {
			parent.$.messager.w('请选择一条记录进行编辑！');
			return;
		}
		
		var dialog = parent.sy.modalDialog({
			title : '编辑活动',
			width : '800',
			height : '600',
			url : '/manager/${sys}/go/indexActEdit?id='+rows[0].id,
			buttons : [ {
				text : '保存',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.submitForm(dialog, table, parent.$);
				}
			} ]
		});
	}
	var delFun = function(){
		var rows = sy.fnGetSelected(table);
		if (rows.length == 0) {
			parent.$.messager.w('请选择需要删除的记录！');
			return;
		}
		parent.$.messager.confirm('询问', '您确定要删除此活动吗？（删除后请手动修改第五张图片的尺寸）', function(r) {
			if (r) {
				var ids = [];
				for ( var i = 0, l = rows.length; i < l; i++) {
					var r = rows[i];
					ids.push(r.id);
				}
				var id = ids.join(',');
				
				$.post(sy.contextPath + '/indexActivity/del', {
					id : id
				}, function() {
					table.fnDraw(false);
				}, 'json');
			}
		});
	}

	var online = function (id,type){
		if (type == 1){
			parent.$.messager.confirm('询问','确定开启此活动吗？',function(r){
				if (r){
					var data = {
							id : id,
							state : 1
					};
					SaveData(data);
				}
			});
		}else {
			parent.$.messager.confirm('询问','确定关闭此活动吗？',function(r){
				if (r){
					var data = {
							id : id,
							state : 0
					};
					SaveData(data);
				}
			});
		}
	}
	
	var changesort = function (id){
		parent.$.messager.prompt(false,'请输入排序数值',function(r){
				if (r){
					if(!UT.isInt(r)){
						parent.$.messager.e('只能输入数字');
						return;
					}
					var data = {
							id : id,
							sortOrder : r
					};
					SaveData(data);
				}
		});
	}
	var exportFun = function(){
		var range = $('#reservation').val();
		var begin = "";
		var end = "";
		if(range){
		 	begin = range.split(' - ')[0]+' 00:00:00';
		 	end =  range.split(' - ')[1]+' 23:59:59';
		}
		var t = "您确定要导出吗？";
		if(range){
			t+="[时间："+range+"]";
		}
		parent.$.messager.confirm('询问', t, function(r) {
			if(r){
				window.location = sy.contextPath+'/order/exportExcel?beginTime='+begin+'&endTime='+end+'&type='+type;
			}
		});
		
	}
	function SaveData(data) {
		$.post(sy.contextPath + '/order/save.do', data, function() {
			table.fnDraw(false);
		}, 'json');
	}
</script>

</body>
</html>
